package facilius.controller.action.nota;

import facilius.model.ServiceLocator;
import facilius.model.pojo.Turma;
import facilius.model.pojo.UsuarioCursoTurma;
import facilius.model.pojo.ValorNota;
import java.util.HashMap;
import java.util.Map;
import org.mentawai.core.BaseAction;

/**
 *
 * @author Graciano
 */
public class NotaShowFormAction extends BaseAction{

    @Override
    public String execute() throws Exception {
        String consequence = ERROR;
        String formAction = "NotaCreate.mtw";
        this.preload();
        try {
            Long idUsuario = input.getLong("idUsuario");
            Long idTurma = input.getLong("idTurma");

            UsuarioCursoTurma usuario = ServiceLocator.getUsuarioCursoTurmaService().readById(idUsuario);
            Turma turma = ServiceLocator.getTurmaService().readById(idTurma);
            
            consequence = SUCCESS;
            output.setValue("formAction", formAction);
            output.setValue("turma", turma.toString());
            output.setValue("aluno", usuario.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return consequence;
    }

    public void preload() throws Exception {
        Map<String, Object> criteria = new HashMap<String, Object>();
        criteria.put("usuarioId", input.getLong("idUsuario"));
        Map<String, String> options = ServiceLocator.getTipoNotaService().getOptions(criteria);
        output.setValue("tipoNotaOptions", options);

        criteria = new HashMap<String, Object>();
        options = ServiceLocator.getUsuarioCursoTurmaService().getOptions(criteria);
        output.setValue("usuarioCursoTurmaOptions", options);
    }

}
